from re_common.baselibrary.utils.core.requests_core import MsgCode

__all__ = ["cnkijournal_cnkiarticle_m_list",
           "chaoxingjournal_chaoxingjournallist_m_list",
           "cnkijournal_cnkijournallist_m_list",
           "article_middlerwares",
           "article_middlerwares2",
           "ref_middlerwares",
           "ref_middlerwares2",
           "on_request_end",
           "cnki_journal_middlerwares",
           "cnki_cnkinet1st_middlerwares",
           "cnkijournal_cnkinet1st_m_list",
           "cnkijournal_cnkinet1starticle_m_list"
           ]

chaoxingjournal_chaoxingjournallist_m_list = []
cnkijournal_cnkiarticle_m_list = ["article_middlerwares",
                                  "article_middlerwares2",
                                  "ref_middlerwares",
                                  "ref_middlerwares2",
                                  "on_request_end"]
# 用于cnkijournallist 级
cnkijournal_cnkijournallist_m_list = ["cnki_journal_middlerwares"]
cnkijournal_cnkinet1st_m_list = ["cnki_cnkinet1st_middlerwares"]

cnkijournal_cnkinet1starticle_m_list = ["article_middlerwares", "article_middlerwares2"]


def article_middlerwares(self):
    """
    验证返回码
    :return:
    """
    if self.html.find('所查找的文献不存在') != -1:
        self.resp_dicts["code"] = MsgCode.NO_RESOURCE
        self.resp_dicts["msg"] = "所查找的文献不存在"
        return False, self.resp_dicts
    return True, self.resp_dicts


def article_middlerwares2(self):
    """
    验证返回码
    :return:
    """
    if self.html.find('所查找的文件不存在') != -1:
        self.resp_dicts["code"] = MsgCode.NO_RESOURCE
        self.resp_dicts["msg"] = "所查找的文件不存在"
        return False, self.resp_dicts
    return True, self.resp_dicts


def ref_middlerwares(self):
    """
    验证返回码
    :return:
    """
    if self.html.find('未找到相关数据') != -1:
        self.resp_dicts["code"] = MsgCode.NO_RESOURCE
        self.resp_dicts["msg"] = "未找到相关数据"
        return False, self.resp_dicts
    return True, self.resp_dicts


def ref_middlerwares2(self):
    """
    :return:
    """
    if self.html.find('无标题页') != -1:
        self.resp_dicts["code"] = MsgCode.NO_RESOURCE
        self.resp_dicts["msg"] = "无标题页"
        return False, self.resp_dicts
    return True, self.resp_dicts


def on_request_end(self):
    if self.html:
        self.html = self.html.replace("'", '"')  # 单引号替换为双引号
    return True, self.resp_dicts


def cnki_journal_middlerwares(self):
    """
        验证返回码
        :return:
    """
    if self.html.find('暂无此期刊') != -1:
        self.resp_dicts["code"] = MsgCode.PARE_NO_DATA
        self.resp_dicts["msg"] = "暂无此期刊"
        return False, self.resp_dicts
    return True, self.resp_dicts


def cnki_cnkinet1st_middlerwares(self):
    """
        验证返回码
        :return:
    """
    if self.html.find('暂无目录信息') != -1:
        self.resp_dicts["code"] = MsgCode.PARE_NO_DATA
        self.resp_dicts["msg"] = "所查找的网络首发显示暂无目录信息"
        return False, self.resp_dicts
    return True, self.resp_dicts
